<!--
 * @Author: your name
 * @Date: 2021-09-07 08:38:38
 * @LastEditTime: 2021-09-09 19:56:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \musicapp\src\components\musicList.vue
-->
<template>
  <div class="musicList">
      <div class="musicList-top">
          <div class="title">发现好歌单</div>
          <div class="more">查看更多</div>
      </div>
      <div class="mlist">
          <van-swipe :loop="false" :width="110">
            <van-swipe-item v-for="item in musicList" :key="item">
                <router-link :to="{path:'/listview',query:{id:item.id}}">
                <div class="img">
                    <img :src="item.picUrl" :alt="item.name">
                    
                </div>
                <div class="name">{{item.name}}</div>
                <div class="count">
                    <svg class="icon"><use xlink:href="#icon-bofang"></use></svg>
                    <span>{{changeValue(item.playCount)}}</span>
                </div>
                </router-link>
            </van-swipe-item>

        </van-swipe>
      </div>
  </div>
</template>

<script>
import {getMusicList} from '@/api/index.js'
import {onMounted, reactive} from 'vue'

export default {
    setup(){
        let musicList = reactive([])
        onMounted(async() => {
            let result = await getMusicList()
            console.log(result.data.result);

            musicList.push(...result.data.result)
            
        })
        function changeValue(num){
            let res = 0
            if(num>=100000000){
                res = num/100000000
                res = res.toFixed(2) + '亿'
            }else if(num>10000){
                res = num/10000
                res = res.toFixed(2)+'万'
            }else{
                res = num
            }
            return res;
        }

        return {
            musicList,
            changeValue
        }
    },

}
</script>

<style scoped lang="less">
.musicList{
    width: 7.5rem;
    padding-left: 0.4rem;
    overflow: hidden;
    .musicList-top{
        padding-right: 0.4rem;
        display: flex;
        justify-content: space-between;
        height: 1rem;
        align-items: center;
        .title{
            font-size: 0.4rem;
            font-weight: 900;
        }
        .more{
            
            border: 1px solid #ccc;
            border-radius: 0.25rem;
            font-size: 0.24rem;
            height: 0.5rem;
            width: 1.2rem;
            text-align: center;
            line-height: 0.5rem;
        }
    }
}
.mlist{
    width: 7.5rem;
    overflow: hidden;
}
.van-swipe .van-swipe-item{
    position: relative;
    padding: 0.2rem 0.2rem 0.2rem 0;
    
    height: 3rem;
    float: left;

    display: flex;
    flex-direction: column;
    .img{

        width: 100%;
        height: 100px;
        img{
            border-radius: 0.2rem;
            width: 100%;
        }
    }
    .name{
         height: 0.6rem;
         width: 100%;
         font-size: 0.24rem;
         line-height: 0.4rem;
    }
    .count{
        position: absolute;
        right:0.25rem;
        top: 0.2rem;
        font-size: 0.24rem;
        color: #ccc;
        display: flex;
        align-items: center;
        .icon{
            fill: #ccc;
        }
    }
}
</style>